import json
import os

with open(os.path.dirname(__file__) + os.sep+'icon_manifest.json', 'r') as f:
    icons = json.load(f)


def get_icon(path: str):
    if (os.path.isdir(path)):
        icon_id = icons["dirs"].get(path.split(os.sep)[-1], "")
        if (icon_id == ""):
            return icons["default"]["dir"]
        return icon_id
    else:
        icon_id = icons["files"].get(path.split(os.sep)[-1], "")
        if (icon_id != ""):
            return icon_id
        icon_id = icons["files"].get(path.split(os.sep)[-1].split(".")[-1], "")
        if (icon_id != ""):
            return icon_id
        return icons["default"]["file"]
